using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BuddhistSchools.DTO.Models.Mapping
{
    public class PagodaMap : EntityTypeConfiguration<Pagoda>
    {
        public PagodaMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            this.Property(t => t.Address)
                .HasMaxLength(200);

            this.Property(t => t.PhoneNumber)
                .HasMaxLength(17);

            // Table & Column Mappings
            this.ToTable("Pagoda");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Address).HasColumnName("Address");
            this.Property(t => t.PhoneNumber).HasColumnName("PhoneNumber");
            this.Property(t => t.ProvinceID).HasColumnName("ProvinceID");

            // Relationships
            this.HasRequired(t => t.Province)
                .WithMany(t => t.Pagodas)
                .HasForeignKey(d => d.ProvinceID);

        }
    }
}
